/**
 * 数列求和，用自己写的链表模板实现
 * 输入包含多个测试用例。每个测试用例包含一个整数 N，然后 N 个整数跟在同一行中。以 0 开头的测试用例将终止输入，并且不会处理此测试用例。
 */

#include <iostream>
#include <stdexcept>

#define eleType int

using namespace std;

struct ListNode
{
    eleType data;
    ListNode *next;
    ListNode(eleType x) : data(x), next(NULL) {}
};

class LinkedList
{
private:
    ListNode *head;
    int size;
public:
    LinkedList() : head(NULL), size(0) {}
    ~LinkedList();

    // 增
    void insert(int nIndex, eleType element);

    // 删
    void remove(int nIndex);

    // 改
    void update(int nIndex, eleType element);

    // 查
    ListNode *find(eleType element);
    ListNode *get(int nIndex);

    // 打印
    void print();

    // 求和函数
    eleType sum();

};

LinkedList::~LinkedList()
{
    ListNode *pTemp = head;
    while (pTemp)
    {
        ListNode *deleNode = pTemp;
        pTemp = pTemp->next;       
        delete deleNode;
    }
}

void LinkedList::insert(int nIndex, eleType element)
{
    if (nIndex < 0 || nIndex > size) 
    {
        throw std::out_of_range("Index position");
    }
    ListNode *newNode = new ListNode(element);
    if (nIndex == 0)
    {
        newNode->next = head;
        head = newNode;
    }
    else 
    {
        ListNode *pTemp = head;
        for (int j = 1; j < nIndex; ++j)
        {
            pTemp = pTemp->next;
        }
        newNode->next = pTemp->next;
        pTemp->next = newNode;
    }
    size++;
}

void LinkedList::remove(int nIndex)
{
    if (nIndex < 0 || nIndex >= size) 
    {
        throw std::out_of_range("Index position");
    }
    if (nIndex == 0)
    {
        ListNode *pDel = head;
        head = head->next;
        delete pDel;
    }
    else
    {
        ListNode *pTemp = head;
        for (int i = 0; i < nIndex; ++i) 
        {
            pTemp = pTemp->next;
        }
        ListNode *pDel = pTemp->next;
        pTemp->next = pDel->next;
        delete pDel;
    }
    size--;
}
void LinkedList::update(int nIndex, eleType element)
{  
    get(nIndex)->data = element;
}

ListNode *LinkedList::find(eleType element)
{
    ListNode *pTemp = head;
    for (int j = 0; j < size; ++j) 
    {
        if (pTemp->data == element) 
        {
            return pTemp;
        }
        pTemp = pTemp->next;
    }
    return NULL;
}

ListNode *LinkedList::get(int nIndex)
{
    if (nIndex < 0 || nIndex >= size)
    {
        throw std::out_of_range("Index position");
    }
    ListNode *pTemp = head;
    for (int j = 0; j < nIndex; ++j) 
    {
        pTemp = pTemp->next;
    }
    return pTemp;
}

void LinkedList::print() 
{
    ListNode *pTemp = head;
    while (pTemp)
    {
        cout << pTemp->data << " ";
        pTemp = pTemp->next;
    }
    cout << endl;
}

eleType LinkedList::sum()
{
    int nSum = 0;
    ListNode *pTemp = head;
    while (pTemp)
    {
        nSum += pTemp->data;
        pTemp = pTemp->next;
    }
    return nSum;
}

int main()
{
    int n;
    while (cin >> n && n)
    {
        LinkedList list;
        for (int i = 0; i < n; ++i) 
        {
            int x;
            cin >> x;
            list.insert(i, x);
        }
        // list.print();
        cout << list.sum() << endl;
    }
    
    return 0;
}